package learningApp.Accessories;

import learningApp.Function.IConcentratedFunction;

public class StaticCalculations {

	public static double CalcNorm2(IConcentratedFunction f, int dimension)
	{
		VariableAssignment tempAssignment;
		double sum = 0.0;
		int ITERATIONS_COUNT = 50;
		//	Perform 50 samples
		for(int counter=0; counter < ITERATIONS_COUNT; counter++)
		{
			tempAssignment = VariableAssignment.GetRandomAssigment(1, dimension);
			double tempAssignmentResult = f.Query(tempAssignment);
			sum += tempAssignmentResult * tempAssignmentResult;
		}
		return sum / ITERATIONS_COUNT;
	}
	
	public static int CalculateRequiredRepetitions(double tau, double eGap, double delta, double infNorm, double norm2, int n)
	{
		double sigma = tau*(1-1/eGap)/(infNorm - tau);
		double numerator = Math.ceil(Math.log(tau*delta / (2*n*eGap*norm2)));
		double denumerator = (infNorm - tau) * (sigma -(1+sigma)*Math.log(1+sigma));
		double iterationsBound = numerator  / denumerator;
		return (int)iterationsBound;
	}
	
}
